
#include "setting_reboot.h"
#include "sys_font.h"
#include "pt_fs.h"
#include "pt_ctl.h"

static ui_setting_reboot_t  ui_set_reboot;


static int setting_reboot_cancel_clicked_event(void)
{
    page_pop();
    root_gesture_enable();

    return 0;
}

static void setting_reboot_cancel_event_callback(lv_event_t* event)
{
    if (event->code == LV_EVENT_CLICKED) {
        debug_d("reboot cancel\n");
        setting_reboot_cancel_clicked_event();
    }
}

static int setting_reboot_yes_clicked_event(void)
{
    pt_reboot();
    return 0;
}

static void setting_reboot_yes_event_callback(lv_event_t* event)
{
    if (event->code == LV_EVENT_CLICKED) {
        debug_d("reboot yes\n");
        setting_reboot_yes_clicked_event();
    }
}


int ui_setting_reboot_create(lv_obj_t *superview)
{
    //**********************************************************************************************
    ui_set_reboot.lab_tip = lv_label_create(superview);
    lv_obj_set_pos(ui_set_reboot.lab_tip,24,104);
    lv_obj_set_size(ui_set_reboot.lab_tip,432,40);
    lv_obj_set_style_text_align(ui_set_reboot.lab_tip,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_reboot.lab_tip,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_reboot.lab_tip,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_reboot.lab_tip, lv_font_get(20), LV_STATE_DEFAULT);
    lv_label_set_text( ui_set_reboot.lab_tip, "是否重启设备？");
    //**********************************************************************************************
    //cancel btn

    ui_set_reboot.bg_cancel = lv_obj_create(superview);

    lv_obj_set_pos(ui_set_reboot.bg_cancel,60,246);
    lv_obj_set_size(ui_set_reboot.bg_cancel,170,50);

	lv_obj_set_style_radius(ui_set_reboot.bg_cancel, 25, LV_PART_MAIN);
	lv_obj_set_style_border_width(ui_set_reboot.bg_cancel, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(ui_set_reboot.bg_cancel, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(ui_set_reboot.bg_cancel, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(ui_set_reboot.bg_cancel, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(ui_set_reboot.bg_cancel, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(ui_set_reboot.bg_cancel, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(ui_set_reboot.bg_cancel, 0,0);
    
    #if 0
    lv_obj_set_style_bg_opa(ui_set_reboot.bg_cancel,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(ui_set_reboot.bg_cancel,LV_OPA_100,0);
    lv_obj_set_style_bg_color(ui_set_reboot.bg_cancel,lv_color_make(0x26,0x7a,0xff),0);
    #endif 

    lv_obj_add_event_cb(ui_set_reboot.bg_cancel, setting_reboot_cancel_event_callback, LV_EVENT_ALL, NULL);
    //**********************************************************************************************
    ui_set_reboot.lab_cancel = lv_label_create(ui_set_reboot.bg_cancel);
    lv_obj_set_pos(ui_set_reboot.lab_cancel,0,5);
    lv_obj_set_size(ui_set_reboot.lab_cancel,170,30);
    lv_obj_set_style_text_align(ui_set_reboot.lab_cancel,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_reboot.lab_cancel,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_reboot.lab_cancel,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_reboot.lab_cancel, lv_font_get(28), LV_STATE_DEFAULT);

    lv_label_set_text(ui_set_reboot.lab_cancel,"取消");
    //**********************************************************************************************
    //**********************************************************************************************
    //yes btn

    ui_set_reboot.bg_yes = lv_obj_create(superview);

    lv_obj_set_pos(ui_set_reboot.bg_yes,275,246);
    lv_obj_set_size(ui_set_reboot.bg_yes,170,50);

	lv_obj_set_style_radius(ui_set_reboot.bg_yes, 25, LV_PART_MAIN);
	lv_obj_set_style_border_width(ui_set_reboot.bg_yes, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(ui_set_reboot.bg_yes, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(ui_set_reboot.bg_yes, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(ui_set_reboot.bg_yes, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(ui_set_reboot.bg_yes, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(ui_set_reboot.bg_yes, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(ui_set_reboot.bg_yes, 0,0);
    
    #if 0
    lv_obj_set_style_bg_opa(ui_set_reboot.bg_yes,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(ui_set_reboot.bg_yes,LV_OPA_100,0);
    lv_obj_set_style_bg_color(ui_set_reboot.bg_yes,lv_color_make(0x26,0x7a,0xff),0);
    #endif 

    lv_obj_add_event_cb(ui_set_reboot.bg_yes, setting_reboot_yes_event_callback, LV_EVENT_ALL, NULL);
    //**********************************************************************************************
    ui_set_reboot.lab_yes = lv_label_create(ui_set_reboot.bg_yes);
    lv_obj_set_pos(ui_set_reboot.lab_yes,0,5);
    lv_obj_set_size(ui_set_reboot.lab_yes,170,30);
    lv_obj_set_style_text_align(ui_set_reboot.lab_yes,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_set_reboot.lab_yes,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_set_reboot.lab_yes,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN); 
    lv_obj_set_style_text_font(ui_set_reboot.lab_yes, lv_font_get(28), LV_STATE_DEFAULT);

    lv_label_set_text(ui_set_reboot.lab_yes,"确认");
    //**********************************************************************************************


    return 0;
}

int ui_setting_reboot_destroy(lv_obj_t *superview)
{
    if(ui_set_reboot.lab_tip){
        lv_obj_del(ui_set_reboot.lab_tip);
        ui_set_reboot.lab_tip = NULL;
    }
    if(ui_set_reboot.bg_cancel){
        lv_obj_del(ui_set_reboot.bg_cancel);
        ui_set_reboot.bg_cancel = NULL;
        ui_set_reboot.lab_cancel = NULL;
    }
    if(ui_set_reboot.bg_yes){
        lv_obj_del(ui_set_reboot.bg_yes);
        ui_set_reboot.bg_yes = NULL;
        ui_set_reboot.lab_yes = NULL;
    }
    
    return 0;
}

static void setting_reboot_on_view_did_load(page_base_t* self)
{
    ui_setting_reboot_create(self->root);
}

static void setting_reboot_on_view_did_unload(page_base_t* self)
{
    ui_setting_reboot_destroy(self->root);
}


static void setting_reboot_on_custom_attr_config(page_base_t* self)
{}
static void setting_reboot_on_view_load(page_base_t* self)
{}
static void setting_reboot_on_view_will_appear(page_base_t* self)
{}
static void setting_reboot_on_view_did_appear(page_base_t* self)
{}
static void setting_reboot_on_view_will_disappear(page_base_t* self)
{}
static void setting_reboot_on_view_did_disappear(page_base_t* self)
{}


static page_vtable_t setting_reboot_param = {
    .on_custom_attr_config  = setting_reboot_on_custom_attr_config,
    .on_view_load           = setting_reboot_on_view_load,
    .on_view_did_load       = setting_reboot_on_view_did_load,
    .on_view_will_appear    = setting_reboot_on_view_will_appear,
    .on_view_did_appear     = setting_reboot_on_view_did_appear,
    .on_view_will_disappear = setting_reboot_on_view_will_disappear,
    .on_view_did_disappear  = setting_reboot_on_view_did_disappear,
    .on_view_did_unload     = setting_reboot_on_view_did_unload,
};


page_vtable_t* lv_page_setting_reboot_create(void)
{
    return &setting_reboot_param;
}
